package mvc.exporter.impl;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.List;

import mvc.core.impl.MachuImage;
import mvc.core.impl.MachuPicchu;
import mvc.exporter.IExporter;
import mvc.imageProcessor.impl.ImageProcessor;

import com.google.inject.Inject;

public class ExportHandler {
	private final IExporter exporter;

	@Inject
	public ExportHandler(IExporter exporter) {
		this.exporter = exporter;
	}

	public void exportImages(List<MachuImage> imageList) throws IOException {
		ImageProcessor imageProcessor = MachuPicchu.getInstance()
				.getImageProcessor();
		if (exporter.prepareSave()) {
			for (MachuImage mi : imageList) {
				long time = System.currentTimeMillis();
				System.out.println("Exporting:	" + mi.getFile().getName());
				BufferedImage coolImage = imageProcessor.processImage(mi, -1, -1);
				exporter.saveImage(coolImage, mi.getFile().getName());
				System.out.println("  completed	"
						+ (System.currentTimeMillis() - time) + " ms");
			}
		}
	}
}
